package com.tang.algorithm.greedy;

import java.util.Arrays;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/6/27 16:18
 * 题解
 * https://leetcode-cn.com/problems/reducing-dishes/solution/zuo-cai-shun-xu-by-leetcode-solution/
 */
public class LeetCode1402 {
    public int maxSatisfaction(int[] satisfaction) {
        Arrays.sort(satisfaction);
        int res = 0;
        int sum = 0;
        for (int i = satisfaction.length - 1; i >= 0; i--) {
            if(sum+satisfaction[i]>0){
                sum+=satisfaction[i];
                res+=sum;
            }else {
                break;
            }
        }
        return res;
    }
}
